package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-19 22:09
 */
public class MaxSubArray {

    public int maxSubArray(int[] nums) {
        int[] res = new int[nums.length];
        res[0] = nums[0];
        int ans = res[0];

        for (int i = 1; i < nums.length; i++) {
            res[i] = nums[i] + Math.max(res[i - 1], 0);
            ans = Math.max(res[i],ans);
        }
        return ans;


    }


}
